﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>@Resources.Global.PageTitle|登录</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link href="~/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <!-- Font Awesome -->
    <link href="~/Content/font-awesome/font-awesome.min.css" rel="stylesheet" />
    <!-- Ionicons -->
    <link href="~/Content/ionicons/ionicons.min.css" rel="stylesheet" />
    <!-- Theme style -->
    <link href="~/Content/AdminLTE.min.css" rel="stylesheet" />
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition login-page">
    <div class="login-box">
        <!-- /.login-logo -->
        <div class="login-box-body">
            <p class="login-box-msg">登录</p>
            <form method="post" id="formLogin">
                <div class="form-group has-feedback">
                    <input type="text" id="txt_account" class="form-control" maxlength="20" placeholder="用户名">
                    <span class="glyphicon glyphicon-user form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" id="txt_password" class="form-control" maxlength="20" placeholder="登录密码">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback clearfix">
                    <input id="txt_code" maxlength="4" type="text" placeholder="验证码"  class="form-control" style="width: 180px; float: left;font-size: 14px;display: block;text-align: left;" >
                    <div style="width: 130px; float: right; padding-top: 9px; padding-left: 14px;">
                        看不清？<a id="switchCode" href="javascript:void(0);" style="text-decoration: none;">换一张</a>
                        <img id="imgcode" class="authcode" src="~/Login/GetAuthCode" width="80" height="25" style="position: absolute; left: 99px; top: 7px;" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <span  id="login_button" class="btn btn-primary btn-block btn-flat">登 录</span>
                    </div>
                </div>
            </form>
            <div class="text-red login_tips"></div>
        </div>
    </div>
    <!-- jQuery 2.2.3 -->
    <script src="~/Scripts/jQuery/jquery-2.2.3.min.js"></script>
    <!-- jQuery cookie -->
    <script src="~/Scripts/cookie/jquery.cookie.js"></script>
    <!-- jQuery md5 -->
    <script src="~/Scripts/md5/jquery.md5.js"></script>
    <!-- Bootstrap 3.3.6 -->
    <script src="~/bootstrap/js/bootstrap.min.js"></script>
    <script>
        (function ($) {
            $.login = {
                formMessage: function (msg) {
                    $('.login_tips').find('.tips_msg').remove();
                    $('.login_tips').append('<div class="tips_msg"><i class="fa"></i>' + msg + '</div>');
                },
                loginClick: function () {
                    var $username = $("#txt_account");
                    var $password = $("#txt_password");
                    var $code = $("#txt_code");
                    if ($username.val() == "") {
                        $username.focus();
                        $.login.formMessage('请输入用户名。');
                        return false;
                    } else if ($password.val() == "") {
                        $password.focus();
                        $.login.formMessage('请输入登录密码。');
                        return false;
                    } else if ($code.val() == "") {
                        $code.focus();
                        $.login.formMessage('请输入验证码。');
                        return false;
                    } else {
                        $("#login_button").attr('disabled', 'disabled').find('span').html("loading...");
                        $.ajax({
                            url: "/Login/CheckLogin",
                            data: { username: $.trim($username.val()), password: $.md5($.trim($password.val())), code: $.trim($code.val()) },
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                if (data.state == "success") {
                                    $("#login_button").find('span').html("登录成功，正在跳转...");
                                    window.setTimeout(function () {
                                        window.location.href = "/Home/Index";
                                    }, 500);
                                } else {
                                    $("#login_button").removeAttr('disabled').find('span').html("登录");
                                    $("#switchCode").trigger("click");
                                    $code.val('');
                                    $.login.formMessage(data.message);
                                }
                            }
                        });
                    }
                },
                init: function () {
                    $("#switchCode").click(function () {
                        $("#imgcode").attr("src", "/Login/GetAuthCode?time=" + Math.random());
                    });
                    var login_error = top.$.cookie('cubic_login_error');
                    if (login_error != null) {
                        switch (login_error) {
                            case "overdue":
                                $.login.formMessage("系统登录已超时,请重新登录");
                                break;
                            case "OnLine":
                                $.login.formMessage("您的帐号已在其它地方登录,请重新登录");
                                break;
                            case "-1":
                                $.login.formMessage("系统未知错误,请重新登录");
                                break;
                        }
                        top.$.cookie('cubic_login_error', '', { path: "/", expires: -1 });
                    }
                    $("#login_button").click(function () {
                        
                        var b = $.login.loginClick();
                        if (b)
                        {
                            $("#formLogin").submit;
                        }
                    });
                    document.onkeydown = function (e) {
                        if (!e) e = window.event;
                        if ((e.keyCode || e.which) == 13) {
                            document.getElementById("login_button").focus();
                            document.getElementById("login_button").click();
                        }
                    }
                }
            };


            $(function () {
                $.login.init();
            });
        })(jQuery);
    </script>
</body>
</html>
